package accs.model.mail;

import java.net.URL;

import accs.model.Account;
import accs.model.AccountChecker;
import accs.model.Context;

public class MailAccountChecker implements AccountChecker {
	private MailChecker checker=new MailChecker();
	
	public MailAccount login(String user, String password, Context ctx) throws Exception {
		MailCheckResult res=checker.checkAdress(user, password);
		
		if(res==MailCheckResult.VALID) {
			return new MailAccount(user, password);
		} else {
			return null;
		}
	}

	public URL getImage() {
		return MailAccountChecker.class.getResource("/accs/gui/img/mail.png");
	}
	
	private class MailAccount implements Account {
		private String username;
		private String password;
		
		public MailAccount(String user, String pass) {
			this.username=user;
			this.password=pass;
		}
		
		public String toString() {
			return username+":"+password;
		}
	}

	public String getName() {
		return "mail";
	}
}